package cn.funeralobjects.common.web.controller.converter;

import cn.funeralobjects.common.enums.SimpleStatus;
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;

import java.beans.PropertyEditorSupport;

/**
 * SimpleStatus的转换器
 *
 * @author FuneralObjects
 * Create date: 2020/4/28 9:15 AM
 */
public class SimpleStatusPropertyEditorRegistrar implements PropertyEditorRegistrar {
    @Override
    public void registerCustomEditors(PropertyEditorRegistry registry) {
        registry.registerCustomEditor(SimpleStatus.class, new SimpleStatusPropertyEditor());
    }

    public static class SimpleStatusPropertyEditor extends PropertyEditorSupport {

        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            setValue(SimpleStatus.of(text));
        }
    }
}
